package com.dhj.streamTest2;

import com.dhj.streamTest.entity.Author;

import java.util.List;
import java.util.Optional;

import static com.dhj.streamTest.entity.AuthorList.getAuthors;

public class Demo6 {

    public static void main(String[] args) {
        List<Author> authors = getAuthors();

        Optional<Author> any = authors.stream().distinct().findAny();
        System.out.println(any.get().getName() + "--" + any.get().getAge());


        System.out.println("--------------------------------------------");


        Optional<Author> any1 = authors.stream().distinct()
                .filter(author -> author.getAge() > 16).findAny();
        System.out.println(any1.get().getName() + "--" + any1.get().getAge());


        System.out.println("--------------------------------------------");


        Optional<Author> any3 = authors.stream().distinct()
                .filter(author -> author.getAge() > 16).findAny();

        any3.ifPresent(author -> System.out.println(author.getName() + "--" + author.getAge()));


    }
}
